@echo off
echo ==========================================
echo Redis COM Component Uninstall Script
echo ==========================================
echo.

echo [1/2] Unregistering Redis COM component...
python redis_com_server.py --unregister
if errorlevel 1 (
    echo WARNING: Failed to unregister COM component normally.
    echo Attempting manual cleanup...

    echo Cleaning up registry entries...
    reg delete "HKEY_CLASSES_ROOT\RedisCOM.Server" /f >nul 2>&1
    reg delete "HKEY_CLASSES_ROOT\CLSID\{*}" /f >nul 2>&1

    echo Clearing Python COM cache...
    python -c "import win32com.client; win32com.client.gencache.EnsureModule(None, None, None, None, bForDemand=False)" >nul 2>&1
)

echo.
echo [2/2] Cleaning up temporary files...
if exist "__pycache__" (
    rmdir /s /q __pycache__
    echo Removed Python cache files.
)

if exist "*.pyc" (
    del /q *.pyc
    echo Removed Python compiled files.
)

echo.
echo ==========================================
echo Uninstall completed!
echo ==========================================
echo.
echo The Redis COM component has been removed from your system.
echo Python packages (pywin32, redis) have been left installed.
echo.
echo To completely remove Python packages, run:
echo   pip uninstall pywin32 redis
echo.
pause
